{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pythreejs import *\n",
    "from ipywidgets.widgets import HBox, VBox, Layout\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Setup our objects\n",
    "mat1 = MeshStandardMaterial(color='#ff0000')\n",
    "mat2 = MeshStandardMaterial(color='#00ff00')\n",
    "mat3 = MeshStandardMaterial(color='#0000ff')\n",
    "mat4 = MeshStandardMaterial(color='#ffff00')\n",
    "mat5 = MeshStandardMaterial(color='#ff00ff')\n",
    "mat6 = MeshStandardMaterial(color='#00ffff')\n",
    "torus = TorusGeometry(radius=12, tube=3, radialSegments=16, tubularSegments=100)\n",
    "mesh1 = Mesh(geometry=torus, material=mat1)\n",
    "mesh2 = Mesh(geometry=torus, material=mat2)\n",
    "mesh3 = Mesh(geometry=torus, material=mat3)\n",
    "mesh4 = Mesh(geometry=torus, material=mat4)\n",
    "mesh5 = Mesh(geometry=torus, material=mat5)\n",
    "mesh6 = Mesh(geometry=torus, material=mat6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "# This will render our meshes, each multiple times, resulting in 30 different renderings\n",
    "# Each of the 30 is a separate widget.  \n",
    "# This test demonstrates:\n",
    "# - rendering shared objects in multiple places\n",
    "# - maintaining interactivity for all renderings\n",
    "# - no prior image is lost because of subsequent renderings\n",
    "VBox(children=[\n",
    "    HBox(children=[\n",
    "        Preview(mesh, _width=150, _height=150, layout=Layout(padding='2px'))\n",
    "        for mesh in [mesh1, mesh2, mesh3, mesh4, mesh5, mesh6]])\n",
    "    for _ in range(5)\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Test using raw WebGLRenderer\n",
    "# Need a scene, cam, and lights to do so\n",
    "scene = Scene()\n",
    "\n",
    "scene.add(mesh1)\n",
    "\n",
    "cam = PerspectiveCamera(position=[0, 0, 50], fov=75)\n",
    "cam.lookAt([0, 0, 0])\n",
    "scene.add(cam)\n",
    "\n",
    "amb = AmbientLight(color=\"#ffffff\", intensity=0.5)\n",
    "point = PointLight(color=\"#ffffff\", intensity=1.0, distance=0.0)\n",
    "point.position = [ -100, 100, 100 ]\n",
    "point.lookAt([0, 0, 0])\n",
    "cam.add(amb)\n",
    "cam.add(point)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Renderer(camera=cam, scene=scene, controls=[OrbitControls(cam)])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "renderer = WebGLRenderer(width=50, height=50)\n",
    "r = renderer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "hboxes = []\n",
    "for i in range(5):\n",
    "    views = []\n",
    "    for j in range(5):\n",
    "        views.append(r)\n",
    "    hbox = HBox(children=views)\n",
    "    hboxes.append(hbox)\n",
    "vbox = VBox(children=hboxes)\n",
    "r.layout.padding = '5px'\n",
    "vbox"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for _ in range(10):\n",
    "    renderer.render(scene, cam)\n",
    "    time.sleep(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
